﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DotNet.Random.IdCard
{
    /// <summary>
    /// 统计局地址随机类，实现了接口IAddressRandService
    /// </summary>
    public class StatisticsAddressRandService : Interface.IAddressRandService
    {
        /// <summary>
        /// Rands this instance.
        /// 随机生成一个地址方法，
        /// 映射到虚方法中，扩展时，可重写
        /// </summary>
        /// <returns>
        /// 返回统计局地址类型
        /// </returns>
        public virtual AddressModel Rand()
        {
            AddressModel data = null;
            var json = Resource.Address;
            var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AddressModel>>(json);
            if (list.Count > 0)
            {
                var intRand = new Int.IntRandService();
                for (int i = 0; i < list.Count; i++)
                {
                    intRand.Serial.Add(i);
                }
                var rand = intRand.Rand();
                data = list[rand];
            }
            return data;
        }
    }

    public class AddressModel
    {
        public int id { get; set; }

        public string num { get; set; }

        public string address { get; set; }
    }
}
